using OpenTK;

namespace ColladaDotNet.OpenTKMapping
{
	public class Sceleton
	{
		public Document Document;

		private Node[] skeleton;

		private string[] skeletonUrls;
		public void Load(string[] skeleton)
		{
			skeletonUrls = skeleton;
			this.skeleton = new Node[skeleton.Length];
		}

		public Matrix4d GetBonePosition(string sid)
		{
			var n = GetBone(sid);
			return n != null ? n.Matrix : Matrix4d.Identity;
		}

		public Node GetBone(string sid)
		{
			for (int i = 0; i < skeleton.Length; ++i)
			{
				if (skeleton[i] == null)
				{
					skeleton[i] = Document.GetElementByUrl<Node>(skeletonUrls[i]);
				}
				if (skeleton[i] != null)
				{
					Node n = skeleton[i].GetElementBySid(sid);
					if (n != null)
					{
						return n;
					}
				}
			}
			return null;
		}
	}
}